package com.atgugui.eduservice.controller.front;

import com.atgugui.commonutils.Result;
import com.atgugui.eduservice.entity.EduCourse;
import com.atgugui.eduservice.entity.EduTeacher;
import com.atgugui.eduservice.service.EduCourseService;
import com.atgugui.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 */
@Api(tags = "在线教育平台首页数据接口层")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexFront")
public class FrontIndexController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    @Cacheable(key="index",value = "'selectIndexList'")
    @ApiOperation(value = "获取首页热门课程和热门讲师数据接口")
    @GetMapping("/index")
    public Result index() {
        // 查询最热门的8门课程数据
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseQueryWrapper);

        // 查询最热门的四个讲师数据
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);

        return Result.ok().data("hotCourses",courseList).data("hotTeachers",teacherList);
    }
}
